<?php /*a:1:{s:81:"D:\phpstudy\PHPTutorial\WWW\d_school\application\admin\view\goods\goods_list.html";i:1558765088;}*/ ?>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <style>
        .layui-table-body {
            overflow: -webkit-paged-x;
        }
    </style>
</head>

<body>
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">商品管理</a>
        <a>
            <cite>商品列表</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form class="layui-form layui-col-space5" style="text-align: center">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="where"  placeholder="请输入商品名称" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="screen">筛选</button>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="reset">重置</button>
                        </div>
                    </form>
                </div>
                <table class="layui-hide" id="test" lay-filter="test"></table>
                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckData">
                            <i class="layui-icon layui-icon-delete"></i>批量删除
                        </button>
                        <button class="layui-btn layui-btn-sm" lay-event="add">
                            <i class="layui-icon layui-icon-add-circle"></i>添加
                        </button>
                    </div>
                </script>
                <script type="text/html" id="barDemo">
                    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                </script>
                <script type="text/html" id="is_home">
                    <input type="checkbox" name="is_home" value="{{d.id}}" lay-skin="switch"
                           lay-text="是|否" lay-filter="is_home" {{ d.is_home == 1 ? 'checked' : '' }}>
                </script>
                <script type="text/html" id="status">
                    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch"
                           lay-text="上架|下架" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
                </script>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['table', 'form'],function() {
        let table = layui.table
            ,form = layui.form;
        table.render({
            elem: '#test'
            ,url:'<?php echo url("Goods/goodsData"); ?>'
            ,toolbar: '#toolbarDemo'
            ,defaultToolbar: ['filter','print']
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true}
                ,{field:'good_name', title:'商品名称'}
                ,{field:'image', title:'商品图片',templet:function (d) {
                        var image = '<div class="layer-photos-demo">\n' +
                            '<img layer-pid="'+ d.id +'" layer-src="' + d.image + '" src="' + d.image + '" width="30px" height="30px" alt="...">\n' +
                            '</div>';
                        return image;
                    }}
                ,{field:'subscription', title:'订阅量'}
                ,{field:'price', title:'商品价格'}
                ,{field:'create_time', title:'创建时间'}
                ,{field:'is_home', title:'首页展示',align:'center',templet:'#is_home'}
                ,{field:'status', title:'状态',align:'center',templet:'#status'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
            ,done: function(res, curr, count){
                layer.photos({
                    photos: '.layer-photos-demo'
                    ,anim:5
                });
            }
        });
        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    let event = checkStatus.data;
                    if (event.length == 0){
                        return false;
                    }
                    let ids = tableCheckedAll(event);
                    layer.confirm('确定删除这 '+ event.length +' 行', function(index){
                        $.post('<?php echo url("goodsDel"); ?>',{id:ids},function (res) {
                            if (res.code){
                                layer.msg(res.msg,{icon:6,time:1000},function () {
                                    table.reload('test');
                                });
                            } else {
                                layer.msg(res.msg,{icon:5,time:3000});
                            }
                        });
                    });
                    break;
                case 'add':
                    xadmin.open('添加','<?php echo url("goodsAdd"); ?>');
                    break;
            }
        });
        //监听行工具事件
        table.on('tool(test)', function(obj){
            let data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定删除这行', function(index){
                    $.post('<?php echo url("goodsDel"); ?>',{id:data.id},function (res) {
                        if (res.code){
                            layer.msg(res.msg,{icon:6,time:1000},function () {
                                table.reload('test');
                            });
                        } else {
                            layer.msg(res.msg,{icon:5,time:3000});
                        }
                    });
                });
            } else if(obj.event === 'edit'){
                xadmin.open('修改','<?php echo url("goodsEdit"); ?>?id='+data.id);
            }
        });
        //监听状态操作
        form.on('switch(is_home)', function(obj){
            let value = obj.elem.checked?1:0;
            let data = {id:this.value,name:this.name,value:value};
            $.post('<?php echo url("goodsStatus"); ?>',data, function (res) {});
        });
        form.on('switch(status)', function(obj){
            let value = obj.elem.checked?1:0;
            let data = {id:this.value,name:this.name,value:value};
            $.post('<?php echo url("goodsStatus"); ?>',data, function (res) {});
        });
        form.on('submit(screen)',function (data) {
            table.reload('test',{
                where:data.field
            });
            return false;
        });
        form.on('submit(reset)',function (data) {
            $('input[name="where"]').val('');
            table.reload('test',{
                where:''
            });
            return false;
        });
    });
</script>

</html>